﻿#ifndef HTTP_CLIENT_H
#define HTTP_CLIENT_H


#include <QWidget>
#include <QObject>
#include <QDebug>
#include <QHttpMultiPart>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QMetaObject>
#include <QEventLoop>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QJsonObject>
#include <QJsonValue>
#include <QJsonArray>
#include <QTime>
#include <QTimer>


class HTTP_client : public QObject
{

    Q_OBJECT

public:
    HTTP_client(QObject *parent = nullptr);

    bool PostRequest(QString key, QString data);

    QString receivePostReply(QNetworkReply *reply);

    //开门
    bool operate_open_door(QString MachineSn,int& error);

    //关门
    bool operate_close_door(QString MachineSn,int& error);

    //true 是开门， false是关门
    //error返回0是开门，返回其他是关门
    bool get_door_state(QString MachineSn,int& error);

    //设置吹气
    bool operate_blow(QString MachineSn, int& error);

    bool get_operate_blow_state(QString MachineSn, int& timeout);

    //获取机台加工状态
    bool operate_get_status(QString MachineSn, int& state);

    //上传DM码
    bool upload_dm_message(QString deviceSN,QString pieceNumber);

private:

    QNetworkAccessManager nam;

    QTime http_time_;

    QTimer* m_requestTimeoutTimer;
};

#endif // HTTP_CLIENT_H
